#include <exception>
#include <iostream>
#include <memory>

struct E : public std::exception
{
   char c_;
   E(char c) : c_(c) {}
};

typedef struct X
{
   char c_;
   X(char c): c_(c) { std::cout << c_; }
   ~X() { std::cout << c_;}
}X;

typedef std::auto_ptr<X> PX;

PX f(char c)
{
   return PX(new X(c));
}

void g(const PX& px)
{
   throw E(px->c_);
}

void h()
{
   PX pa = f('a');
   try
   {
      PX pb = pa;
      g(f('b'));
   }
   catch (const E& e)
   {
      std::cout << e.c_;
      throw;
   }
}

int main()
{
   try
   {
      h();
   }
   catch (const std::exception &)
   {
      std::cout << 'c';
   }
   catch (const E& e)
   {
      std::cout << e.c_;
   }
}


